<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace OSS\Model;

class LifecycleConfig implements XmlConfig
{
    private $rules;
    public function parseFromXml($strXml)
    {
        $this->rules = [];
        $xml = simplexml_load_string($strXml);
        if(!isset($xml->Rule)) {
            return NULL;
        }
        $this->rules = [];
        foreach ($xml->Rule as $rule) {
            $id = strval($rule->ID);
            $prefix = strval($rule->Prefix);
            $status = strval($rule->Status);
            $actions = [];
            foreach ($rule as $key => $value) {
                if($key === "ID" || $key === "Prefix" || $key === "Status") {
                } else {
                    $action = $key;
                    $timeSpec = NULL;
                    $timeValue = NULL;
                    foreach ($value as $timeSpecKey => $timeValueValue) {
                        $timeSpec = $timeSpecKey;
                        $timeValue = strval($timeValueValue);
                    }
                    $actions[] = new LifecycleAction($action, $timeSpec, $timeValue);
                }
            }
            $this->rules[] = new LifecycleRule($id, $prefix, $status, $actions);
        }
        return NULL;
    }
    public function serializeToXml()
    {
        $xml = new \SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><LifecycleConfiguration></LifecycleConfiguration>");
        foreach ($this->rules as $rule) {
            $xmlRule = $xml->addChild("Rule");
            $rule->appendToXml($xmlRule);
        }
        return $xml->asXML();
    }
    public function addRule($lifecycleRule)
    {
        if(!isset($lifecycleRule)) {
            throw new \OSS\Core\OssException("lifecycleRule is null");
        }
        $this->rules[] = $lifecycleRule;
    }
    public function __toString()
    {
        return $this->serializeToXml();
    }
    public function getRules()
    {
        return $this->rules;
    }
}

?>